'use strict';

module.exports = {
  dumpError(err) {
    if (typeof err === 'object') {
      if (err.message) {
        console.log('\nMessage: ' + err.message);
      }
      if (err.stack) {
        console.log('\nStacktrace:');
        console.log('====================');
        console.log(err.stack);
      }
    } else {
      console.log('dumpError :: argument is not an object');
    }
  },
  registerRouter(data) {
    const { app } = this;
    const { action_name, path, middleware_name, controller_name} = data;
    try {
      if (middleware_name) {
        const middlewares = middleware_name.split(','); // 多个中间件用逗号分隔
        app.router[action_name](path, ...middlewares, controller_name);
      } else {
        app.router[action_name](path, controller_name);
      }
      return true;
    } catch (error) {
      return false;
    }
    
  }
};
